/**
 * Loading widget creator.
 * 
 * Implements a widget which shows a loading animation.
 */

function LoadingWidget(options) {
	if(!options) options = {};
	if(!options.id) options.id = Widget.uid();
	if(!options.label) options.label = "Loading";

	var that = Widget(options);

	var labelId = options.id + "-label";
	var errorId = options.id + "-error";

	that.getHtml = function() {
		return sprintf('<div class="loading" id="%s"><div class="label" id="%s">%s</div><div class="error" id="%s" style="display: none;"></div></div>', options.id, labelId, options.label, errorId);
	};
	
	that.showError = function() {
		mwl.hide('#' + labelId);
		mwl.show('#' + errorId);
	};
	
	that.showLoadingMwl = function() {
		return sprintf("mwl.hide('#%s');mwl.show('#%s');", errorId, labelId);
	}
	
	that.setError = function(content) {
		$('#' + errorId).html(content);
	}
	
	return that;
}
